<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>16.7km/s</title>
    <style>
        .reader {
            box-sizing: border-box;
            height: 50vh;
            width: 100%;
            background: #eee;
            padding: 15px;
        }

        .qrcode-warp {
            display: none;
            margin-top: 5vh;
            justify-content: center;
        }
    </style>
</head>

<body>
    <textarea class="reader" placeholder="输入 回车 扫码">
    </textarea>

    <div class="qrcode-warp">
        <div id="qrcode"></div>
    </div>
    <p style="text-align: center;color: #999;">双向传输敬请期待!</p>
    <script type="text/javascript" src="./qrcode.min.js"></script>
    <script type="text/javascript">
        var qrWarp = document.getElementsByClassName('qrcode-warp')[0];
        var qrcode = new QRCode("qrcode", {
            text: "16.7km/s",
            colorDark: "#000000",
            colorLight: "#ffffff",
        });

        var reader = document.getElementsByClassName("reader")[0];
        reader.innerText = "";
        reader.focus();
        // Execute a function when the user presses a key on the keyboard
        reader.addEventListener("keypress", function (event) {
            if (event.key === "Enter") {
                try {
                    qrcode.makeCode(reader.value.trim());
                    qrWarp.style.display = "flex";
                } catch (e) {
                    console.log(e);
                    alert("文本过长请重新输入");
                    qrWarp.style.display = "none";
                    reader.focus();
                }
            } 
        });
    </script>

</body>

</html>